from django.conf import settings
from django.core.files.storage import Storage


class FastDFSStorage(Storage):

    def __init__(self, fdfs_base_url=None):
        # 初始化
        # if not option:
        #     option = settings.CUSTOM_STORAGE_OPTIONS
        # pass
        self.fdfs_base_url = fdfs_base_url or settings.FDFS_BASE_URL

    def _open(self, name, mode='rb'):
        """
        文档描述，此方法必须重写
        :param name: 文件路径
        :param mode: 打开文件方法
        :return: None
        """
        # 不需要打开文件重写，pass即可
        pass

    def _save(self, name, content):
        """
        文档描述，此方法必须重写
        :param name: 文件路径
        :param content: 文件二进制内容
        :return: None
        """
        pass

    def url(self, name):
        """
        返回name所指文件的绝对URL
        :param name: 要读取文件的引用:group1/M00/00/00/wKhnnlxw_gmAcoWmAAEXU5wmjPs35.jpeg
        :return: http://192.168.103.158:8888/group1/M00/00/00/wKhnnlxw_gmAcoWmAAEXU5wmjPs35.jpeg
        """
        return settings.FDFS_BASE_URL + name

    def exists(self, name):
        pass
